package com.bangyu.monitor.modular.system.service;

import com.bangyu.monitor.modular.system.entity.*;
import com.bangyu.monitor.modular.system.mapper.OriginalDataMapper;
import com.bangyu.monitor.modular.system.mapper.WeightPayloadMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Auther: zhangxue
 * @Date: 19/4/1 13:47
 * @Description:
 */
@Service
@Slf4j
public class WeightPayloadService extends ServiceImpl<WeightPayloadMapper, WeightPayload> {

//    private static final ExecutorService executor = Executors.newFixedThreadPool(2);


    public void insertBatch(List<WeightPayload> datas){
        if(CollectionUtils.isNotEmpty(datas)){
            log.info("重型荷载数据入库{}条",datas);
            this.baseMapper.batchInsert(datas);
        }
    }

    //异步批量保存
//    public void asynchInsertBatch(List<WeightPayload> datas){
//        executor.execute(new Runnable() {
//            @Override public void run() {
//                insertBatch(datas);
//            }
//        });
//    }

    //判断梁经过重型荷载之后是否恢复
    public boolean isRecover(String beamNo){
        List<NotRecoverWeightPayload> weightPayloads = queryNotRecovered(beamNo);

        return CollectionUtils.isEmpty(weightPayloads);

    }

    /**
     * 查询没有回复的重型荷载数据
     * @param beamNo
     * @return
     */
    public List<NotRecoverWeightPayload> queryNotRecovered(String beamNo){
        return this.baseMapper.queryByBeamNoAndNotRecover(beamNo);
    }


    public void setRecover(Long id,Integer recoverType,Date recoverTime){
        this.baseMapper.updateRecover(id,recoverType,recoverTime);
    }

    //已经恢复的数据
    public List<RecoverInfoDto> queryRecovered(String beamNo,Integer startDate,Integer endDate){
        return baseMapper.queryRecovered(beamNo,startDate,endDate);
    }

    /**
     * 查询每种极限级别的数量
     * @param beamNo
     * @param startDate
     * @param endDate
     * @return
     */
    public List<ExtremityCount> extremityCounts(String beamNo,Integer startDate,Integer endDate){
        return baseMapper.queryCountByExtremityLevel(beamNo,startDate,endDate);
    }


}
